import Vue from "vue";
import App from "./App.vue";
import router from "./router";
// 引入axios 库
import axios from "axios";
// 绑定到原型
Vue.prototype.$axios = axios;
// 设置基准路径
axios.defaults.baseURL = "http://127.0.0.1:3000";
// axios.defaults.baseURL = 'http://liangwei.tech:3000'
Vue.config.productionTip = false;

// 引入ElementUI 组件库
import ElementUI from "element-ui";
// 引入css
import "element-ui/lib/theme-chalk/index.css";
// 注册组件库
Vue.use(ElementUI);
// 添加路由守卫
router.beforeEach((to, from, next) => {
  // console.log(to);
  //console.log(from);

  if (to.path != "/login" && !localStorage.getItem("token")) {
    router.push("/login");
  } else {
    next();
  }
});
new Vue({
  router,
  render: function(h) {
    return h(App);
  },
}).$mount("#app");
